<template>
  <div class="count">
    <h2>当前求和为：{{ countStore.sum }}</h2>
    <h3>欢迎来到：{{ countStore.school }}</h3>
    <h3>坐落于：{{ countStore.address }}</h3>
    <select v-model.number="n">
      <option value="1">1</option>
      <option value="2">2</option>
      <option value="3">3</option>
    </select>
    <button @click="add">加</button>
    <button @click="minus">减</button>
    <ul>
      <li v-for="talk in talkList" :key="talk.id">{{ talk.title }}</li>
    </ul>
  </div>
</template>

<script setup lang="ts" name="Count">
import { ref } from "vue";

import { useTalkStore } from "@/store/loveTalk";

import { useCountStore } from "@/store/count";
const countStore = useCountStore();

const {talkList} = useTalkStore()
let n = ref(1); // 用户选择的数字


function add() {
  // 1.直接修改数据
  // countStore.sum += 1;
  // 2.批量修改数据
  // countStore.$patch({
  //   sum:88,
  //   school:"北京航空航天大学-1",
  //   address:"北京市海淀区学院路37号-1"
  // })
  // 3.使用active方法修改数据
  countStore.increment(n.value);
}


// function minus() {
//   sum.value -= n.value;
// }
</script>

<style scoped>
.count {
  background-color: skyblue;
  padding: 10px;
  border-radius: 10px;
  box-shadow: 0 0 10px;
}
select,
button {
  margin: 0 5px;
  height: 25px;
}
</style>
